#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
    int n = 0, m = 0;
    scanf("%d %d", &n, &m);
    char a[100][100] = { 0 };
    int b[100][100] = { 0 };
    int i = 0, j = 0, count = 0;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            scanf("%c", &a[i][j]);
        }
    }
    while (m--)
    {
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
            {
                if (a[i][j] == '@' && !b[i][j])
                {
                    if (i + 1 < n && a[i + 1][j] == '.')
                    {
                        a[i + 1][j] = '@';
                        count++;
                        b[i + 1][j] = 1;
                    }
                    if (i - 1 > 0 && a[i - 1][j] == '.')
                    {
                        a[i - 1][j] = '@';
                        count++;
                        b[i - 1][j] = 1;
                    }
                    if (j + 1 < n && a[i][j + 1] == '.')
                    {
                        a[i][j + 1] = '@';
                        count++;
                        b[i][j + 1] = 1;
                    }
                    if (j - 1 > 0 && a[i][j - 1] == '.')
                    {
                        a[i][j - 1] = '@';
                        count++;
                        b[i][j - 1] = 1;
                    }
                }
            }
        }
    }
    printf("%d", count);
    return 0;
}